diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-18 07:52:02 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-18 07:52:02 +0000 |
| commit | 48a2255bfc45ffcfb0b39ffefdd57cbacf8b36df (patch) | |
| tree | 0c88b7c126138233875e8d372a4e999e49c38a62 /app/api/notifications/[id] | |
| parent | 2ef02e27dbe639876fa3b90c30307dda183545ec (diff) | |
(대표님) 파일관리변경, 클라IP추적, 실시간알림, 미들웨어변경, 알림API
Diffstat (limited to 'app/api/notifications/[id]')
| -rw-r--r-- | app/api/notifications/[id]/deleate/route.ts | 34 | ||||
| -rw-r--r-- | app/api/notifications/[id]/read/route.ts | 34 |
2 files changed, 68 insertions, 0 deletions
diff --git a/app/api/notifications/[id]/deleate/route.ts b/app/api/notifications/[id]/deleate/route.ts new file mode 100644 index 00000000..21123c78 --- /dev/null +++ b/app/api/notifications/[id]/deleate/route.ts @@ -0,0 +1,34 @@ +// app/api/notifications/[id]/delete/route.ts +import { NextRequest, NextResponse } from 'next/server'; +import { getServerSession } from 'next-auth'; +import { authOptions } from "@/app/api/auth/[...nextauth]/route" +import { deleteNotification } from '@/lib/notification/service'; + +export async function DELETE( + request: NextRequest, + { params }: { params: { id: string } } +) { + try { + const session = await getServerSession(authOptions); + if (!session?.user?.id) { + return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + } + + const deletedNotification = await deleteNotification(params.id, session.user.id); + + if (!deletedNotification) { + return NextResponse.json( + { error: 'Notification not found' }, + { status: 404 } + ); + } + + return NextResponse.json({ success: true }); + } catch (error) { + console.error('Error deleting notification:', error); + return NextResponse.json( + { error: 'Failed to delete notification' }, + { status: 500 } + ); + } +}
\ No newline at end of file diff --git a/app/api/notifications/[id]/read/route.ts b/app/api/notifications/[id]/read/route.ts new file mode 100644 index 00000000..ba894fad --- /dev/null +++ b/app/api/notifications/[id]/read/route.ts @@ -0,0 +1,34 @@ +// app/api/notifications/[id]/read/route.ts +import { NextRequest, NextResponse } from 'next/server'; +import { getServerSession } from 'next-auth'; +import { authOptions } from "@/app/api/auth/[...nextauth]/route" +import { markNotificationAsRead } from '@/lib/notification/service'; + +export async function PATCH( + request: NextRequest, + { params }: { params: { id: string } } +) { + try { + const session = await getServerSession(authOptions); + if (!session?.user?.id) { + return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + } + + const notification = await markNotificationAsRead(params.id, session.user.id); + + if (!notification) { + return NextResponse.json( + { error: 'Notification not found' }, + { status: 404 } + ); + } + + return NextResponse.json({ success: true, notification }); + } catch (error) { + console.error('Error marking notification as read:', error); + return NextResponse.json( + { error: 'Failed to mark notification as read' }, + { status: 500 } + ); + } +}
\ No newline at end of file |
